#include "GUI_Touch.h"

Touch_Stack_t  Touch_Stack;  //全局触摸栈
uint8_t Touch_Stack_Init_Success_Flag=0;


Touch_Status_t Touch_Status;

Touch_Slider_t  Touch_Slider;


void GUI_Touch_Init()
{

	Touch_Status.x=0;
	Touch_Status.y=0;
	Touch_Status.Ispress=false;


	Touch_Slider.status=TOUCH_Start;
	Touch_Slider.offset=0;

    Touch_Status_Stack_Init();

	
}
 bool Touch_is_pressed(void)
{
    if(Touch_Status.Ispress==true)
    {
    	return true;
    }
    else
    {
    	return false;
    }

}


Touch_Activity_t  Touch_Activity_Get()
{
	//Touch_Stack->Top_Index
}


void Touch_Status_Stack_Init()
{


    uint8_t i=0;

    //Touch_Stack_Init_Success_Flag=0;

	Touch_Stack.Top_Index=0;
	for(i=0;i<Touch_Status_Stack_Size;i++)
	{
	   Touch_Stack.Touch_Status_Stack[i].Ispress=false;
	   Touch_Stack.Touch_Status_Stack[i].x=0;
	   Touch_Stack.Touch_Status_Stack[i].y=0;
	}

	Touch_Stack_Init_Success_Flag=1;
}


bool Touch_Status_Stack_Is_Empty(Touch_Stack_t *Touch_Stack)
{
   if(Touch_Stack->Top_Index==0)
   	return true;
   else
   	return false;
}



bool Touch_Status_Stack_Is_Full(Touch_Stack_t *Touch_Stack)
{
   if(Touch_Stack->Top_Index>=Touch_Status_Stack_Size)
   	return true;
   else
   	return false;
}


bool Touch_Status_Stack_Push(Touch_Stack_t *Touch_Stack,Touch_Status_t *touch_status)
{
//printf("-----------------------------%s\r\n",__FUNCTION__);

   if(Touch_Status_Stack_Is_Full(Touch_Stack)==true)  //判断栈是否已满
   {
       //printf("%s------------Touch_Status_Stack_Is_Full\r\n",__FUNCTION__);
        return false;
   }


   if(Touch_is_pressed()!=true)
   	{
   	    //printf("%s------------Touch_is_pressed\r\n",__FUNCTION__);
   		return false;
   	}
    

   Touch_Stack->Touch_Status_Stack[Touch_Stack->Top_Index].Ispress=touch_status->Ispress;
   Touch_Stack->Touch_Status_Stack[Touch_Stack->Top_Index].x=touch_status->x;
   Touch_Stack->Touch_Status_Stack[Touch_Stack->Top_Index].y=touch_status->y;
   Touch_Stack->Top_Index++;//栈顶指针增加


#if 0
   printf("Touch_Stack->Touch_Status_Stack[%d].Ispress=%d\r\n",Touch_Stack->Top_Index,touch_status->Ispress);
   printf("Touch_Stack->Touch_Status_Stack[%d].x=%d\r\n",      Touch_Stack->Top_Index,touch_status->x);
   printf("Touch_Stack->Touch_Status_Stack[%d].y=%d\r\n",      Touch_Stack->Top_Index,touch_status->y);
#endif
   return true;
 	 
}

uint8_t Touch_Status_Stack_Num(Touch_Stack_t *Touch_Stack)
{
	return Touch_Stack->Top_Index;
}


uint8_t Touch_Status_Stack_Is_Init()
{
	return Touch_Stack_Init_Success_Flag;

}


void Touch_Status_Stack_data_Anslaysic(Touch_Stack_t *Touch_Stack)
{
  int xoffset=0,yoffset=0;
  xoffset 	=  Touch_Stack->Touch_Status_Stack[Touch_Status_Stack_Size-1].x   -  Touch_Stack->Touch_Status_Stack[0].x;
  yoffset 	=  Touch_Stack->Touch_Status_Stack[Touch_Status_Stack_Size-1].y   -  Touch_Stack->Touch_Status_Stack[0].y;

#if 0
  if(xoffset>SCROLL_X_OFFSET)
  //if( (xoffset>SCROLL_X_OFFSET)&&( (yoffset>SCROLL_Y_OFFSET)||(yoffset<-SCROLL_Y_OFFSET)) )
  {

		Touch_Slider.status=TOUCH_Right;
		Touch_Slider.offset=abs(xoffset);

	  Touch_Stack_Init_Success_Flag=0;

	 printf("-----------------------------Move_Right,xoffset=%d\r\n",xoffset);
	//return  Move_Right;

  }
  else if (xoffset<-SCROLL_X_OFFSET)
	 // if( (xoffset<-SCROLL_X_OFFSET)&&( (yoffset>SCROLL_Y_OFFSET)||(yoffset<-SCROLL_Y_OFFSET)) )
  {



		Touch_Slider.status=TOUCH_Left;
		Touch_Slider.offset=abs(xoffset);

         Touch_Stack_Init_Success_Flag=0;
		 printf("-----------------------------Move_Left,xoffset=%d\r\n",xoffset);
	//return  Move_Left;
  }


#endif
   //if( (yoffset>SCROLL_Y_OFFSET)&&( (xoffset>SCROLL_X_OFFSET)||(xoffset<-SCROLL_X_OFFSET)) )
  if(yoffset>SCROLL_Y_OFFSET)
  {

		Touch_Slider.status=TOUCH_Down;
		Touch_Slider.offset=abs(yoffset);
     Touch_Stack_Init_Success_Flag=0;
	  printf("-----------------------------Move_Down,yoffset=%d\r\n",yoffset);
    // return Move_Down;
  }

#if 1
  else  if(yoffset<-SCROLL_Y_OFFSET)
  //if( (yoffset<-SCROLL_Y_OFFSET)&&( (xoffset>SCROLL_X_OFFSET)||(xoffset<-SCROLL_X_OFFSET)) )
  {
		Touch_Slider.status=TOUCH_Up;
		Touch_Slider.offset=abs(yoffset);

    Touch_Stack_Init_Success_Flag=0;
	  printf("-----------------------------Move_Up,yoffset=%d\r\n",yoffset);
   //return Move_Up;
  }
#endif

}



